package com.yuhs.zixing.study.design.pattern.dp002.structural.s006.flyweight.f002;

import java.util.HashMap;

/**
 * @description:
 * @author: yuhs
 * @date: 2022/5/2 11:06 AM
 */
public class SignInfoFactory002 {
    //池容器
    private static HashMap<String, SignInfo002> pool = new HashMap<String, SignInfo002>();

    //报名信息的对象工厂
    @Deprecated
    public static SignInfo002 getSignInfo() {
        return new SignInfo002();
    }

    //从池中获得对象
    public static SignInfo002 getSignInfo(String key) {
        //设置返回对象
        SignInfo002 result = null;
        //池中没有该对象，则建立，并放入池中
        if (!pool.containsKey(key)) {
            System.out.println(key + "----建立对象，并放置到池中");
            result = new SignInfo4Pool002(key);
            pool.put(key, result);
        } else {
            result = pool.get(key);
            System.out.println(key + "---直接从池中取得");
        }
        return result;
    }
}
